﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace Document_Management.tianche
{
    public partial class main : Form
    {
        static string connectionstring = ConfigurationManager.ConnectionStrings["庫存管理"].ConnectionString;
        
        bool b天車Search, b天車Insert, b天車Edit, b天車Del;
        
        public main(bool b天車Search, bool b天車Insert, bool b天車Edit, bool b天車Del)
        {
            InitializeComponent();
            this.b天車Search = b天車Search;
            this.b天車Insert = b天車Insert;
            this.b天車Edit = b天車Edit;
            this.b天車Del = b天車Del;

        }
    
        public void main_Load(object sender, EventArgs e)
        {
            group天車人員輸入.Visible = false;
            groupbox天車輸入.Visible = false;
            groupbox天車保養.Visible = false;
            groupbox天車點檢輸入.Visible = false;
            groupboxtiancheweixiushuru.Visible = false;
            groupbox巡檢輸入.Visible = false;
           // btnReporttianche.Visible = true;
                //al.GETALL("天車", dtgv天車List);
            PublicClass.LoadAllNoneProcedure("Viewtiancheinfo", dtgv天車List);//
            PublicClass.LoadAllNoneProcedure("Viewtiancherenyuan", dtgv天車人員List);//天車人員

            PublicClass.LoadAllNoneProcedure("天車功能", dtgv天車功能);

            PublicClass.LoadAllNoneProcedure("天車巡檢", dtgv天車巡檢List);

            PublicClass.LoadAllNoneProcedure("天車廠牌", dtgv天車廠牌List);

            PublicClass.LoadAllNoneProcedure("天車成本中心", dtgv天車成本中心List);

            PublicClass.LoadAllNoneProcedure("天車維修", dtgv天車維修List);

            PublicClass.LoadAllNoneProcedure("天車部門", dtgv天車部門List);

            PublicClass.LoadAllNoneProcedure("天車額定荷重", dtgv額定荷重);

            PublicClass.LoadAllNoneProcedure("天車點檢", dtgv天車點檢List);
            PublicClass.LoadAllNoneProcedure("天車保養", dtgv天車保養List);

            if (!b天車Search)
            {
                btnSearchMain.Enabled = false;
                btn_查詢_天車人員.Enabled = false;
                btn_search_tianchexunjian.Enabled = false;
                btn_search_tiancheweixiu.Enabled = false;
                btn_Search_天車點檢.Enabled = false;
                btn_search_天車保養.Enabled = false;
            }
            if (!b天車Insert)
            {
                btn_新增_天車保養.Enabled = false;
                btn_新增_天車地點.Enabled = false;
                btn_新增_額定荷重.Enabled = false;
                btn_新增_天車部門.Enabled = false;
                btn新增_天車維修.Enabled = false;
                btn_新增_天車成本中心.Enabled = false;
                btn_新增_天車廠牌.Enabled = false;
                btn_新增_天車巡檢.Enabled = false;
                btn_新增_天車功能.Enabled = false;
                btn_新增_天車人員.Enabled = false;
                btn_新增_天車.Enabled = false;
            }
            if (!b天車Edit)
            {
                btn_更新_天車保養.Enabled = false;
                btn_更新_天車點檢.Enabled = false;
                btn_更新_額定荷重.Enabled = false;
                btn_更新_天車部門.Enabled = false;
                btn_更新_天車維修.Enabled = false;
                btn_更新_天車成本中心.Enabled = false;
                btn_更新_天車廠牌.Enabled = false;
                btn_更新_天車巡檢.Enabled = false;
                btn_更新_天車功能.Enabled = false;
                btn_更新_天車人員.Enabled = false;
                btn_更新_天車.Enabled = false;
            }
            if (!b天車Del)
            {
                btn_刪除_天車保養.Enabled = false;
                btn_刪除_天車點檢.Enabled = false;
                btn_刪除_額定荷重.Enabled = false;
                btn_刪除_天車部門.Enabled = false;
                btn_刪除_天車維修.Enabled = false;
                btn_刪除_天車成本中心.Enabled = false;
                btn_刪除_天車廠牌.Enabled = false;
                btn_刪除_天車巡檢.Enabled = false;
                btn_刪除_天車功能.Enabled = false;
                btn_刪除_天車人員.Enabled = false;
                btn_刪除_天車.Enabled = false;
            }
        }
   
        private void btn_新增_天車_Click(object sender, EventArgs e)
        {
            if (!b天車Insert) btn_新增_天車.Enabled = false;
            try
            {
                if (txt天車編號_天車.Text == "")
                {
                    MessageBox.Show("您必須輸入天車編號","訊息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                    txt天車編號_天車.Focus();
                    return;
                }
                if (txt天車人員_天車.Text == "")
                {
                    MessageBox.Show("您必須輸入天車人員", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt天車人員_天車.Focus();
                    return;
                }
                if (txt額定荷重_天車.Text == "")
                {
                    MessageBox.Show("您必須輸入額定荷重", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt額定荷重_天車.Focus();
                    return;
                }
                if (txt功能_天車.Text == "")
                {
                    MessageBox.Show("您必須輸入天車功能", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt功能_天車.Focus();
                    return;
                }
                if (txt廠牌_天車.Text == "")
                {
                    MessageBox.Show("您必須輸入天車廠牌", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt廠牌_天車.Focus();
                    return;
                }
                //int iNumber;
                //bool bNumber =int.TryParse(txt數量.Text,out iNumber);
                //if (!bNumber)
                //{
                //    MessageBox.Show("您輸入數量(int)不正確","訊息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                //    txt數量.Focus();
                //    return;
                //}

                //insert action
                string strcmd = String.Format("insert into 天車 values(N'{0}',N'{1}',N'{2}',N'{3}',N'{4}',N'{5}',N'{6}',N'{7}',N'{8}')", txt天車編號_天車.Text, txt天車人員_天車.Text, txt額定荷重_天車.Text, txt功能_天車.Text, txt廠牌_天車.Text, txt生產序號_天車.Text, dtp生產日期_天車.Value.ToShortDateString(), dtp安裝日期_天車.Value.ToShortDateString(), dtp初次取證日_天車.Value.ToShortDateString());
                PublicClass.InsertEditDeleteCommand("新增", strcmd, "Viewtiancheinfo", dtgv天車List);
                PublicClass.SearchTiancheInfo(dtgv天車List, txt天車編號s.Text, txt額定荷重s.Text, txt功能s.Text, txt廠牌s.Text, txt生產序號s.Text, dtp生產日期天車from.Value, dtp生產日期天車to.Value, dtp安裝日期天車from.Value, dtp安裝日期天車to.Value, dtp初次取證日from.Value, dtp初次取證日天車to.Value, txt部門s.Text, txt成本中心s.Text, txt天車人員s.Text, txt電話s.Text);
                txt天車編號_天車.ResetText();
                txt天車人員_天車.ResetText();
                txt額定荷重_天車.ResetText();
                txt功能_天車.ResetText();
                txt廠牌_天車.ResetText();
                txt生產序號_天車.ResetText();
                dtp生產日期_天車.Value = DateTime.Now;
                dtp安裝日期_天車.Value = DateTime.Now;
                dtp初次取證日_天車.Value = DateTime.Now;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #region
        public void xoatextbox()
        {
            label23.Text = "";
            label24.Text = "";
            label25.Text = "";
            label26.Text = "";
            label71.Text = "";
            txt天車編號s.Text = "";
            txt生產序號s.Text = "";
            txt天車人員s.Text = "";
            txt額定荷重s.Text = "";
            txt功能s.Text = "";
            txt廠牌s.Text = "";
            txt天車編號_天車.Text = "";
            txt天車人員_天車.Text = "";
            txt額定荷重_天車.Text = "";
            txt功能_天車.Text = "";
            txt廠牌_天車.Text = "";

            txt生產序號_天車.Text = "";
            txt天車編號_天車.Enabled = true;
            txt天車人員_天車.Enabled = true;
            txt額定荷重_天車.Enabled = true;
            txt功能_天車.Enabled = true;
            txt廠牌_天車.Enabled = true;

            txt生產序號_天車.Enabled = true;
        }
        public void disable()
        {
            txt天車編號_天車.Enabled = false;
            txt天車人員_天車.Enabled = false;
            txt額定荷重_天車.Enabled = false;
            txt功能_天車.Enabled = false;
            txt廠牌_天車.Enabled = false;

            txt生產序號_天車.Enabled = false;
        }
        #endregion
        private void btn_刪除_天車_Click(object sender, EventArgs e)
        {
            if (!b天車Del) btn_刪除_天車.Enabled = false;
            try
            {
                int r = dtgv天車List.CurrentCell.RowIndex;
                string id = dtgv天車List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("delete from 天車 where 天車編號=N'{0}'",id);
                PublicClass.InsertEditDeleteCommand("刪除", strcmd, "天車", dtgv天車List);
                PublicClass.SearchTiancheInfo(dtgv天車List, txt天車編號s.Text, txt額定荷重s.Text, txt功能s.Text, txt廠牌s.Text, txt生產序號s.Text, dtp生產日期天車from.Value, dtp生產日期天車to.Value, dtp安裝日期天車from.Value, dtp安裝日期天車to.Value, dtp初次取證日from.Value, dtp初次取證日天車to.Value, txt部門s.Text, txt成本中心s.Text, txt天車人員s.Text, txt電話s.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }


        private void btn_新增_天車功能_Click(object sender, EventArgs e)
        {
            if (!b天車Insert) btn_新增_天車功能.Enabled = false;
            try
            {
                if (txt功能代號.Text == "")
                {
                    MessageBox.Show("您必須輸入功能代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt功能代號.Focus();
                    return;
                }
                if (txt功能名稱.Text == "")
                {
                    MessageBox.Show("您必須輸入功能名稱", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt功能名稱.Focus();
                    return;
                }
                string strcmd = String.Format("insert into 天車功能 values(N'{0}',N'{1}')",txt功能代號.Text,txt功能名稱.Text);
                PublicClass.InsertEditDeleteCommand("新增", strcmd, "天車功能", dtgv天車功能);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_新增_天車巡檢_Click(object sender, EventArgs e)
        {
            if (!b天車Insert) btn_新增_天車巡檢.Enabled = false;
            try
            {
                string strcmd = String.Format("insert into 天車巡檢(巡檢日期,天車編號,備註) values(N'{0}',N'{1}',N'{2}')", dtp巡檢日期.Value.ToShortDateString(), txt天車編號_天車巡檢.Text, txt備註_天車巡檢.Text);
                PublicClass.InsertEditDeleteCommand("新增", strcmd, "天車巡檢", dtgv天車巡檢List);
                PublicClass.SearchByOne("天車巡檢", "巡檢日期", dtgv天車巡檢List, txt天車id.Text, dtp巡檢日期from.Value, dtp巡檢日期to.Value);
                txt天車編號_天車巡檢.ResetText();
                dtp巡檢日期.ResetText();
                txt備註_天車巡檢.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_新增_天車廠牌_Click(object sender, EventArgs e)
        {
            if (!b天車Insert) btn_新增_天車廠牌.Enabled = false;
            try
            {
                if(txt廠牌代號.Text=="")
                {
                    MessageBox.Show("您必須輸入廠牌代號","訊息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    txt廠牌代號.Focus();
                    return;
                }
                if (txt廠牌名稱.Text == "")
                {
                    MessageBox.Show("您必須輸入廠牌名稱", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txt廠牌名稱.Focus();
                    return;
                }
                string strcmd = String.Format("insert into 天車廠牌 values(N'{0}',N'{1}')", txt廠牌代號.Text, txt廠牌名稱.Text);
                PublicClass.InsertEditDeleteCommand("新增", strcmd, "天車廠牌", dtgv天車廠牌List);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void 天車成本中心_Click(object sender, EventArgs e)
        {
            if (!b天車Insert) btn_新增_天車成本中心.Enabled = false;
            try
            {
                if (txt成本中心代號.Text == "")
                {
                    MessageBox.Show("您必須輸入成本中心代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txt成本中心代號.Focus();
                    return;
                }
                if (txt天車成本中心名稱.Text == "")
                {
                    MessageBox.Show("您必須輸入天車成本中心名稱", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txt天車成本中心名稱.Focus();
                    return;
                }
                string strcmd = String.Format("insert into 天車成本中心 values(N'{0}',N'{1}')", txt成本中心代號.Text, txt天車成本中心名稱.Text);
                PublicClass.InsertEditDeleteCommand("新增", strcmd, "天車成本中心", dtgv天車成本中心List);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void btn新增_天車維修_Click(object sender, EventArgs e)
        {
            if (!b天車Insert) btn新增_天車維修.Enabled = false;
            try
            {
                string strcmd = String.Format("insert into 天車維修 values(N'{0}',N'{1}',N'{2}')",txt天車編號_天車維修.Text, dtp維修日期.Value.ToShortDateString(), txt備註_天車維修.Text);
                PublicClass.InsertEditDeleteCommand("新增", strcmd, "天車維修", dtgv天車維修List);
                PublicClass.SearchByOne("天車維修", "維修日期", dtgv天車維修List, _txt天車編號s.Text, dtp天車維修from.Value, dtp天車維修to.Value);
                dtp維修日期.ResetText();
                txt天車編號_天車維修.ResetText();
                txt備註_天車維修.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
    
        private void btn_新增_天車點檢_Click(object sender, EventArgs e)
        {
            if (!b天車Insert) btn_新增_天車地點.Enabled = false;
            try
            {
                string strcmd = String.Format("insert into 天車點檢(天車編號,點檢日期,備註) values(N'{0}',N'{1}',N'{2}')", txt天車代號_天車點檢.Text,dtp點檢日期.Value.ToShortDateString(),txt備註_天車點檢.Text);
                PublicClass.InsertEditDeleteCommand("新增", strcmd, "天車點檢", dtgv天車點檢List);
                PublicClass.SearchByOne("天車點檢", "點檢日期", dtgv天車點檢List, _txt天車代號_天車點檢.Text, dtp點檢日期from.Value, dtp點檢日期to.Value);//update search
                txt天車代號_天車點檢.ResetText();
                dtp點檢日期.ResetText();
                txt備註_天車點檢.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
           
        }

        private void btn_新增_額定荷重_Click(object sender, EventArgs e)
        {
            if (!b天車Insert) btn_新增_額定荷重.Enabled = false;
            try
            {
                if (txt額定荷重代號.Text == "")
                {
                    MessageBox.Show("必須輸入額定荷重代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt額定荷重代號.Focus();
                    return;

                }
                if (txt額定荷重名稱.Text == "")
                {
                    MessageBox.Show("必須輸入額定荷重名稱", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt額定荷重名稱.Focus();
                    return;
                }
                string strcmd = String.Format("insert into 天車額定荷重 values(N'{0}',N'{1}')", txt額定荷重代號.Text, txt額定荷重名稱.Text);
                PublicClass.InsertEditDeleteCommand("新增", strcmd, "天車額定荷重", dtgv額定荷重);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        }



        private void btn_刪除_天車功能_Click(object sender, EventArgs e)
        {
            if (!b天車Del) btn_刪除_天車功能.Enabled = false;
            try
            {
                int r = dtgv天車功能.CurrentCell.RowIndex;
                string id = dtgv天車功能.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("delete from 天車功能 where 功能代號=N'{0}'",id);
                PublicClass.InsertEditDeleteCommand("刪除", strcmd, "天車功能", dtgv天車功能);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_刪除_天車巡檢_Click(object sender, EventArgs e)
        {
            if (!b天車Del) btn_刪除_天車巡檢.Enabled = false;
            try
            {
                int r = dtgv天車巡檢List.CurrentCell.RowIndex;
                string str天車代號 = dtgv天車巡檢List.Rows[r].Cells[0].Value.ToString();
                DateTime dt巡檢日期 = (DateTime)dtgv天車巡檢List.Rows[r].Cells[1].Value;
                string strcmd = String.Format("delete from 天車巡檢 where 天車編號=N'{0}'and 巡檢日期=N'{1}'",str天車代號,dt巡檢日期.ToShortDateString());
                PublicClass.InsertEditDeleteCommand("刪除", strcmd, "天車巡檢", dtgv天車巡檢List);
                PublicClass.SearchByOne("天車巡檢", "巡檢日期", dtgv天車巡檢List, txt天車id.Text, dtp巡檢日期from.Value, dtp巡檢日期to.Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_刪除_天車廠牌_Click(object sender, EventArgs e)
        {
            if (!b天車Del) btn_刪除_天車廠牌.Enabled = false;
            try
            {
                int r = dtgv天車廠牌List.CurrentCell.RowIndex;
                string id = dtgv天車廠牌List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("delete from 天車廠牌 where 廠牌代號=N'{0}'",id);
                PublicClass.InsertEditDeleteCommand("刪除", strcmd, "天車廠牌", dtgv天車廠牌List);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        

        private void btn_更新_天車功能_Click(object sender, EventArgs e)
        {
            if (!b天車Edit) btn_更新_天車功能.Enabled = false;
            try
            {
                if (txt功能代號.Text == "")
                {
                    MessageBox.Show("您必須輸入功能代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt功能代號.Focus();
                    return;
                }
                if (txt功能名稱.Text == "")
                {
                    MessageBox.Show("您必須輸入功能名稱", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt功能名稱.Focus();
                    return;
                }
                int r = dtgv天車功能.CurrentCell.RowIndex;
                string id = dtgv天車功能.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("update 天車功能 set 功能代號=N'{0}',功能名稱=N'{1}' where 功能代號=N'{2}'", txt功能代號.Text, txt功能名稱.Text, id);
                PublicClass.InsertEditDeleteCommand("更新",strcmd,"天車功能",dtgv天車功能);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_刪除_天車成本中心_Click(object sender, EventArgs e)
        {
            if (!b天車Del) btn_刪除_天車成本中心.Enabled = false;
            try
            {
                int r = dtgv天車成本中心List.CurrentCell.RowIndex;
                string id = dtgv天車成本中心List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("delete from 天車成本中心 where 成本中心代號=N'{0}'", id);
                PublicClass.InsertEditDeleteCommand("刪除", strcmd, "天車成本中心", dtgv天車成本中心List);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void btn_更新_天車成本中心_Click(object sender, EventArgs e)
        {
            if (!b天車Edit) btn_更新_天車成本中心.Enabled = false;
            try
            {
                if (txt成本中心代號.Text == "")
                {
                    MessageBox.Show("您必須輸入成本中心代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txt成本中心代號.Focus();
                    return;
                }
                if (txt天車成本中心名稱.Text == "")
                {
                    MessageBox.Show("您必須輸入天車成本中心名稱", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txt天車成本中心名稱.Focus();
                    return;
                }
                int r = dtgv天車成本中心List.CurrentCell.RowIndex;
                string id = dtgv天車成本中心List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("update 天車成本中心 set 成本中心代號=N'{0}',天車成本中心名稱=N'{1}' where 成本中心代號=N'{2}'", txt成本中心代號.Text, txt天車成本中心名稱.Text, id);
                PublicClass.InsertEditDeleteCommand("更新", strcmd, "天車成本中心", dtgv天車成本中心List);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void btn_刪除_天車維修_Click(object sender, EventArgs e)
        {
            if (!b天車Del) btn_刪除_天車維修.Enabled = false;
            try
            {
                int r = dtgv天車維修List.CurrentCell.RowIndex;
                DateTime dt維修日期 = (DateTime)dtgv天車維修List.Rows[r].Cells[1].Value;
                string str天車編號 = dtgv天車維修List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("delete from 天車維修 where 維修日期=N'{0}' and 天車編號=N'{1}'", dt維修日期.ToShortDateString(), str天車編號);
                PublicClass.InsertEditDeleteCommand("刪除", strcmd, "天車維修", dtgv天車維修List);
                PublicClass.SearchByOne("天車維修", "維修日期", dtgv天車維修List, _txt天車編號s.Text, dtp天車維修from.Value, dtp天車維修to.Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void btn_更新_天車維修_Click(object sender, EventArgs e)
        {
            if (!b天車Edit) btn_更新_天車維修.Enabled = false;
            try
            {
                int r = dtgv天車維修List.CurrentCell.RowIndex;
                DateTime dt維修日期 = (DateTime)dtgv天車維修List.Rows[r].Cells[1].Value;
                string str天車編號 = dtgv天車維修List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("update 天車維修 set 維修日期=N'{0}',天車編號=N'{1}',備註=N'{2}' where 維修日期=N'{3}' and 天車編號=N'{4}'", dtp維修日期.Value.ToShortDateString(), txt天車編號_天車維修.Text, txt備註_天車維修.Text, dt維修日期.ToShortDateString(), str天車編號);
                PublicClass.InsertEditDeleteCommand("更新", strcmd, "天車維修", dtgv天車維修List);
                PublicClass.SearchByOne("天車維修", "維修日期", dtgv天車維修List, _txt天車編號s.Text, dtp天車維修from.Value, dtp天車維修to.Value);
                dtp維修日期.ResetText();
                txt天車編號_天車維修.ResetText();
                txt備註_天車維修.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
               
        }

        private void btn_刪除_額定荷重_Click(object sender, EventArgs e)
        {
            if (!b天車Del) btn_刪除_額定荷重.Enabled = false;
            try
            {
                int r = dtgv額定荷重.CurrentCell.RowIndex;
                string id = dtgv額定荷重.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("delete from 天車額定荷重 where 額定荷重代號=N'{0}'", id);
                PublicClass.InsertEditDeleteCommand("刪除", strcmd, "天車額定荷重", dtgv額定荷重);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_更新_額定荷重_Click(object sender, EventArgs e)
        {
            if(!b天車Edit)btn_更新_額定荷重.Enabled=false;
            try
            {
                if (txt額定荷重代號.Text == "")
                {
                    MessageBox.Show("必須輸入額定荷重代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt額定荷重代號.Focus();
                    return;

                }
                if (txt額定荷重名稱.Text == "")
                {
                    MessageBox.Show("必須輸入額定荷重名稱", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt額定荷重名稱.Focus();
                    return;
                }
                int r = dtgv額定荷重.CurrentCell.RowIndex;
                string id = dtgv額定荷重.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("update 天車額定荷重 set 額定荷重代號='{0}',額定荷重名稱='{1}' where 額定荷重代號=N'{2}'", txt額定荷重代號.Text, txt額定荷重名稱.Text, id);
                PublicClass.InsertEditDeleteCommand("新增", strcmd, "天車額定荷重", dtgv額定荷重);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_更新_天車點檢_Click(object sender, EventArgs e)
        {
            if (!b天車Edit) btn_更新_天車點檢.Enabled = false;
            try
            {
                int r = dtgv天車點檢List.CurrentCell.RowIndex;
                DateTime dt點檢日期 = (DateTime)dtgv天車點檢List.Rows[r].Cells[1].Value;
                //string strdt點檢日期 = dt點檢日期.ToShortDateString();
                string str天車編號 = dtgv天車點檢List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("update 天車點檢 set 點檢日期=N'{0}',天車編號=N'{1}',備註=N'{2}' where 點檢日期=N'{3}' and 天車編號=N'{4}' ", dtp點檢日期.Value.ToShortDateString(), txt天車代號_天車點檢.Text, txt備註_天車點檢.Text, dt點檢日期.ToShortDateString(), str天車編號);
                PublicClass.InsertEditDeleteCommand("更新", strcmd, "天車點檢", dtgv天車點檢List);
                PublicClass.SearchByOne("天車點檢", "點檢日期", dtgv天車點檢List, _txt天車代號_天車點檢.Text, dtp點檢日期from.Value, dtp點檢日期to.Value);//update search
                txt天車代號_天車點檢.ResetText();
                dtp點檢日期.ResetText();
                txt備註_天車點檢.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
           

        }

        private void btn_刪除_天車點檢_Click(object sender, EventArgs e)
        {
            if (!b天車Del) btn_刪除_天車點檢.Enabled = false;
            try
            {
                int r = dtgv天車點檢List.CurrentCell.RowIndex;
                DateTime dt點檢日期 = (DateTime)dtgv天車點檢List.Rows[r].Cells[1].Value;

                string str天車編號 = dtgv天車點檢List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("delete from 天車點檢 where 點檢日期=N'{0}' and 天車編號=N'{1}'", dt點檢日期.ToShortDateString(), str天車編號);
                PublicClass.InsertEditDeleteCommand("刪除", strcmd, "天車點檢", dtgv天車點檢List);
                PublicClass.SearchByOne("天車點檢", "點檢日期", dtgv天車點檢List, _txt天車代號_天車點檢.Text, dtp點檢日期from.Value, dtp點檢日期to.Value);//update search
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
    
        }

        private void btn_新增_天車部門_Click(object sender, EventArgs e)
        {
            if (!b天車Insert) btn_新增_天車部門.Enabled = false;
            try
            {
                if (txt部門代號.Text == "")
                {
                    MessageBox.Show("必須輸入txt部門代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt部門代號.Focus();
                    return;

                }
                if (txt部門名稱.Text == "")
                {
                    MessageBox.Show("必須輸入部門名稱", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt部門名稱.Focus();
                    return;
                }
                string strcmd = String.Format("insert into 天車部門 values(N'{0}',N'{1}')", txt部門代號.Text, txt部門名稱.Text);
                PublicClass.InsertEditDeleteCommand("新增", strcmd, "天車部門", dtgv天車部門List);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void btn_刪除_天車部門_Click(object sender, EventArgs e)
        {
            if (!b天車Del) btn_刪除_天車部門.Enabled = false;
            try
            {
                int r = dtgv天車部門List.CurrentCell.RowIndex;
                string id = dtgv天車部門List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("delete from 天車部門 where 部門代號=N'{0}'", id);
                PublicClass.InsertEditDeleteCommand("刪除", strcmd, "天車部門", dtgv天車部門List);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_更新_天車部門_Click(object sender, EventArgs e)
        {
            if (!b天車Edit) btn_更新_天車部門.Enabled = false;
            try
            {
                if (txt部門代號.Text == "")
                {
                    MessageBox.Show("必須輸入txt部門代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt部門代號.Focus();
                    return;

                }
                if (txt部門名稱.Text == "")
                {
                    MessageBox.Show("必須輸入部門名稱", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt部門名稱.Focus();
                    return;
                }
                int r = dtgv天車部門List.CurrentCell.RowIndex;
                string id = dtgv天車部門List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("update 天車部門 set 部門代號=N'{0}',部門名稱=N'{1}' where 部門代號=N'{2}'", txt部門代號.Text, txt部門名稱.Text, id);
                PublicClass.InsertEditDeleteCommand("更新", strcmd, "天車部門", dtgv天車部門List);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_更新_天車巡檢_Click(object sender, EventArgs e)
        {
            if (!b天車Edit) btn_更新_天車巡檢.Enabled = false;
            try
            {
                int r = dtgv天車巡檢List.CurrentCell.RowIndex;
                string str天車代號 = dtgv天車巡檢List.Rows[r].Cells[0].Value.ToString();
                DateTime dt巡檢日期 = (DateTime)dtgv天車巡檢List.Rows[r].Cells[1].Value;
                string strcmd = String.Format("update 天車巡檢 set 天車編號=N'{0}',巡檢日期=N'{1}',備註=N'{2}' where 天車編號=N'{3}'and 巡檢日期=N'{4}'",txt天車編號_天車巡檢.Text,dtp巡檢日期.Value.ToShortDateString(),txt備註_天車巡檢.Text, str天車代號, dt巡檢日期.ToShortDateString());
                PublicClass.InsertEditDeleteCommand("更新",strcmd,"天車巡檢",dtgv天車巡檢List);
                PublicClass.SearchByOne("天車巡檢", "巡檢日期", dtgv天車巡檢List, txt天車id.Text, dtp巡檢日期from.Value, dtp巡檢日期to.Value);
                txt天車編號_天車巡檢.ResetText();
                dtp巡檢日期.ResetText();
                txt備註_天車巡檢.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void button11_Click(object sender, EventArgs e)
        {
           
        }


        private void btn_更新_天車_Click(object sender, EventArgs e)
        {
            if (!b天車Edit) btn_更新_天車.Enabled = false;
            try
            {
                if (txt天車編號_天車.Text == "")
                {
                    MessageBox.Show("您必須輸入天車編號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt天車編號_天車.Focus();
                    return;
                }
                if (txt天車人員_天車.Text == "")
                {
                    MessageBox.Show("您必須輸入天車人員", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt天車人員_天車.Focus();
                    return;
                }
                if (txt額定荷重_天車.Text == "")
                {
                    MessageBox.Show("您必須輸入額定荷重", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt額定荷重_天車.Focus();
                    return;
                }
                if (txt功能_天車.Text == "")
                {
                    MessageBox.Show("您必須輸入天車功能", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt功能_天車.Focus();
                    return;
                }
                if (txt廠牌_天車.Text == "")
                {
                    MessageBox.Show("您必須輸入天車廠牌", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt廠牌_天車.Focus();
                    return;
                }
                //int iNumber;
                //bool bNumber = int.TryParse(txt數量.Text, out iNumber);
                //if (!bNumber)
                //{
                //    MessageBox.Show("您輸入數量(int)不正確", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //    txt數量.Focus();
                //    return;
                //}
                //update action
                int r = dtgv天車List.CurrentCell.RowIndex;
                string id = dtgv天車List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("update 天車 set 天車編號=N'{0}',天車人員代號=N'{1}',額定荷重代號=N'{2}',功能代號=N'{3}',廠牌代號=N'{4}',生產序號=N'{5}',生產日期=N'{6}',安裝日期=N'{7}',初次取證日=N'{8}'where 天車編號=N'{9}'", txt天車編號_天車.Text, txt天車人員_天車.Text, txt額定荷重_天車.Text, txt功能_天車.Text, txt廠牌_天車.Text, txt生產序號_天車.Text, dtp生產日期_天車.Value.ToShortDateString(), dtp安裝日期_天車.Value.ToShortDateString(), dtp初次取證日_天車.Value.ToShortDateString(),id);
                PublicClass.InsertEditDeleteCommand("更新", strcmd, "Viewtiancheinfo", dtgv天車List);
                PublicClass.SearchTiancheInfo(dtgv天車List, txt天車編號s.Text, txt額定荷重s.Text, txt功能s.Text, txt廠牌s.Text, txt生產序號s.Text, dtp生產日期天車from.Value, dtp生產日期天車to.Value, dtp安裝日期天車from.Value, dtp安裝日期天車to.Value, dtp初次取證日from.Value, dtp初次取證日天車to.Value, txt部門s.Text, txt成本中心s.Text, txt天車人員s.Text, txt電話s.Text);
                txt天車編號_天車.ResetText();
                txt天車人員_天車.ResetText();
                txt額定荷重_天車.ResetText();
                txt功能_天車.ResetText();
                txt廠牌_天車.ResetText();
                txt生產序號_天車.ResetText();
                dtp生產日期_天車.Value = DateTime.Now;
                dtp安裝日期_天車.Value = DateTime.Now;
                dtp初次取證日_天車.Value = DateTime.Now;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

      
        private void dtgv天車部門List_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //int i = e.RowIndex;
            //giatrithaydoi = dtgv天車部門List.Rows[i].Cells[0].Value.ToString();
            //txt部門代號.Text = dtgv天車部門List.Rows[i].Cells[0].Value.ToString();
            //txt部門名稱.Text = dtgv天車部門List.Rows[i].Cells[1].Value.ToString();
        }

        private void tab天車_SelectedIndexChanged(object sender, EventArgs e)
        {
            PublicClass.setRowNumber(dtgv天車List);
            if (tab天車.SelectedIndex == 1)
            {
                PublicClass.LoadAllNoneProcedure("Viewtiancherenyuan", dtgv天車人員List);//天車人員
                PublicClass.setRowNumber(dtgv天車人員List);
            }
            if (tab天車.SelectedIndex == 2)
            {
                PublicClass.LoadAllNoneProcedure("天車功能", dtgv天車功能);
                PublicClass.setRowNumber(dtgv天車功能);
            }
            if (tab天車.SelectedIndex == 3)
            {
                PublicClass.LoadAllNoneProcedure("天車巡檢", dtgv天車巡檢List);
                PublicClass.setRowNumber(dtgv天車巡檢List);
            }
            if (tab天車.SelectedIndex == 4)
            {
                PublicClass.LoadAllNoneProcedure("天車廠牌", dtgv天車廠牌List);
                PublicClass.setRowNumber(dtgv天車廠牌List);
            }
            if (tab天車.SelectedIndex == 5)
            {
                PublicClass.LoadAllNoneProcedure("天車成本中心", dtgv天車成本中心List);
                PublicClass.setRowNumber(dtgv天車成本中心List);
            }
            if (tab天車.SelectedIndex == 6)
            {
                PublicClass.LoadAllNoneProcedure("天車維修", dtgv天車維修List);
                PublicClass.setRowNumber(dtgv天車維修List);
            }
            if (tab天車.SelectedIndex == 7)
            {
                PublicClass.LoadAllNoneProcedure("天車部門", dtgv天車部門List);
                PublicClass.setRowNumber(dtgv天車部門List);
            }
            if (tab天車.SelectedIndex == 8)
            {
                PublicClass.LoadAllNoneProcedure("天車額定荷重", dtgv額定荷重);
                PublicClass.setRowNumber(dtgv額定荷重);
            }
            if (tab天車.SelectedIndex == 9)
            {
                PublicClass.LoadAllNoneProcedure("天車點檢", dtgv天車點檢List);
                PublicClass.setRowNumber(dtgv天車點檢List);
            }
            if (tab天車.SelectedIndex == 10)
            {
                PublicClass.LoadAllNoneProcedure("天車保養", dtgv天車保養List);
                PublicClass.setRowNumber(dtgv天車保養List);
            }
  
        }

    
        private void dtgv額定荷重_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //try
            //{
            //    int i = e.RowIndex;
            //    giatrithaydoi = dtgv額定荷重.Rows[i].Cells[0].Value.ToString();
            //    txt額定荷重代號.Text = dtgv額定荷重.Rows[i].Cells[0].Value.ToString();
            //    txt額定荷重名稱.Text = dtgv額定荷重.Rows[i].Cells[1].Value.ToString();
            //}
            //catch
            //{
            //}
        }
   
        private void dtgv額定荷重_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
               // giatrithaydoi = dtgv額定荷重.Rows[i].Cells[0].Value.ToString();
                txt額定荷重代號.Text = dtgv額定荷重.Rows[i].Cells[0].Value.ToString();
                txt額定荷重名稱.Text = dtgv額定荷重.Rows[i].Cells[1].Value.ToString();
            }
            catch
            {
            }
        }

        private void dtgv天車點檢List_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
                DateTime dt = (DateTime)dtgv天車點檢List.Rows[i].Cells[1].Value;
                dtp點檢日期.Value = dt;
                txt天車代號_天車點檢.Text = dtgv天車點檢List.Rows[i].Cells[0].Value.ToString();
                txt備註_天車點檢.Text = dtgv天車點檢List.Rows[i].Cells[2].Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_清除_天車額定荷重_Click(object sender, EventArgs e)
        {
            try
            {
                txt額定荷重代號.ResetText();
                txt額定荷重名稱.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void btn_清除_天車部門_Click(object sender, EventArgs e)
        {
            try
            {
                txt部門代號.ResetText();
                txt部門名稱.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgv天車地點List_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgv天車點檢List);
        }

        private void dtgv額定荷重_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgv額定荷重);
        }

        private void dtgv天車部門List_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
                //giatrithaydoi = dtgv天車部門List.Rows[i].Cells[0].Value.ToString();
                txt部門代號.Text = dtgv天車部門List.Rows[i].Cells[0].Value.ToString();
                txt部門名稱.Text = dtgv天車部門List.Rows[i].Cells[1].Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgv天車部門List_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgv天車部門List);
        }

        private void dtgv天車維修List_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
                //giatrithaydoi = dtgv天車維修List.Rows[i].Cells[1].Value.ToString();
                dtp維修日期.Value = (DateTime)dtgv天車維修List.Rows[i].Cells[1].Value;
               
                txt天車編號_天車維修.Text = dtgv天車維修List.Rows[i].Cells[0].Value.ToString();
                txt備註_天車維修.Text = dtgv天車維修List.Rows[i].Cells[2].Value.ToString();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgv天車維修List_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgv天車維修List);
        }

        private void btn_清除_天車成本中心_Click(object sender, EventArgs e)
        {
            try
            {
                txt天車成本中心名稱.ResetText();
                txt成本中心代號.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgv天車成本中心List_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
                //giatrithaydoi = dtgv天車成本中心List.Rows[i].Cells[0].Value.ToString();
                txt成本中心代號.Text = dtgv天車成本中心List.Rows[i].Cells[0].Value.ToString();
                txt天車成本中心名稱.Text = dtgv天車成本中心List.Rows[i].Cells[1].Value.ToString();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgv天車成本中心List_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgv天車成本中心List);
        }

        private void btn_更新_天車廠牌_Click(object sender, EventArgs e)
        {
            if (!b天車Edit) btn_更新_天車廠牌.Enabled = false;
            try
            {
                if (txt廠牌代號.Text == "")
                {
                    MessageBox.Show("您必須輸入廠牌代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txt廠牌代號.Focus();
                    return;
                }
                if (txt廠牌名稱.Text == "")
                {
                    MessageBox.Show("您必須輸入廠牌名稱", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txt廠牌名稱.Focus();
                    return;
                }
                int r = dtgv天車廠牌List.CurrentCell.RowIndex;
                string id = dtgv天車廠牌List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("update 天車廠牌 set 廠牌代號=N'{0}',廠牌名稱=N'{1}' where 廠牌代號=N'{2}'", txt廠牌代號.Text, txt廠牌名稱.Text,id);
                PublicClass.InsertEditDeleteCommand("更新", strcmd, "天車廠牌", dtgv天車廠牌List);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_清除_天車廠牌_Click(object sender, EventArgs e)
        {
            try
            {
                txt廠牌代號.ResetText();
                txt廠牌名稱.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgv天車廠牌List_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
               // giatrithaydoi = dtgv天車廠牌List.Rows[i].Cells[0].Value.ToString();
                txt廠牌代號.Text = dtgv天車廠牌List.Rows[i].Cells[0].Value.ToString();
                txt廠牌名稱.Text = dtgv天車廠牌List.Rows[i].Cells[1].Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgv天車廠牌List_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgv天車廠牌List);
        }

        private void dtgv天車巡檢List_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
                //giatrithaydoi = dtgv天車巡檢List.Rows[i].Cells[0].Value.ToString();
                txt天車編號_天車巡檢.Text = dtgv天車巡檢List.Rows[i].Cells[0].Value.ToString();
                dtp巡檢日期.Text = dtgv天車巡檢List.Rows[i].Cells[1].Value.ToString();
                txt備註_天車巡檢.Text = dtgv天車巡檢List.Rows[i].Cells[2].Value.ToString();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgv天車巡檢List_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgv天車巡檢List);
        }

        private void btn_清除_天車功能_Click(object sender, EventArgs e)
        {
            try
            {

                txt功能代號.ResetText();
                txt功能名稱.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgv天車功能_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
                // giatrithaydoi = dtgv天車功能.Rows[I].Cells[0].Value.ToString();
                txt功能代號.Text = dtgv天車功能.Rows[i].Cells[0].Value.ToString();
                txt功能名稱.Text = dtgv天車功能.Rows[i].Cells[1].Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgv天車功能_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgv天車功能);
        }

        private void btn_changeHide_Click(object sender, EventArgs e)
        {
            try
            {
                if (btn_changeHide.Text == "+")
                {
                    btn_changeHide.Text = "-";
                    group天車人員輸入.Visible = true;
                }
                else
                {
                    btn_changeHide.Text = "+";
                    group天車人員輸入.Visible = false;
                    txt天車人員代號.ResetText();
                    txt人員姓名.ResetText();
                    txt成本中心代號_天車人員.ResetText();
                    txt電話號碼.ResetText();
                    txt部門代號_天車人員.ResetText();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_新增_天車人員_Click(object sender, EventArgs e)
        {
            if(!b天車Insert)btn_新增_天車人員.Enabled=false;
            try
            {
                if (txt天車人員代號.Text == "")
                {
                    MessageBox.Show("您必須輸入人員代號","訊息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                    txt天車人員代號.Focus();
                    return;
                }

                if (txt成本中心代號_天車人員.Text == "")
                {
                    MessageBox.Show("您必須輸入成本中心代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt成本中心代號_天車人員.Focus();
                    return;
                }
                if (txt部門代號_天車人員.Text == "")
                {
                    MessageBox.Show("您必須輸入部門代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt部門代號_天車人員.Focus();
                    return;
                }
                string strcmd = String.Format("insert into 天車人員 values(N'{0}',N'{1}',N'{2}',N'{3}',N'{4}')", txt天車人員代號.Text, txt人員姓名.Text, txt部門代號_天車人員.Text, txt成本中心代號_天車人員.Text, txt電話號碼.Text);
                PublicClass.InsertEditDeleteCommand("新增", strcmd, "Viewtiancherenyuan", dtgv天車人員List);//天車人員
                PublicClass.SearchTiancherenyuan(dtgv天車人員List, _txt天車人員代號.Text, _txt人員姓名.Text, _txt部門名稱.Text, _txt成本中心名稱.Text, _txt電話號碼.Text);
                txt天車人員代號.ResetText();
                txt人員姓名.ResetText();
                txt成本中心代號_天車人員.ResetText();
                txt電話號碼.ResetText();
                txt部門代號_天車人員.ResetText();

            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_更新_天車人員_Click(object sender, EventArgs e)
        {
            if (!b天車Edit) btn_更新_天車人員.Enabled = false;
            try
            {
                if (txt天車人員代號.Text == "")
                {
                    MessageBox.Show("您必須輸入人員代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt天車人員代號.Focus();
                    return;
                }

                if (txt成本中心代號_天車人員.Text == "")
                {
                    MessageBox.Show("您必須輸入成本中心代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt成本中心代號_天車人員.Focus();
                    return;
                }
                if (txt部門代號_天車人員.Text == "")
                {
                    MessageBox.Show("您必須輸入部門代號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt部門代號_天車人員.Focus();
                    return;
                }
                int r = dtgv天車人員List.CurrentCell.RowIndex;
                string id = dtgv天車人員List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("update 天車人員 set 天車人員代號=N'{0}',人員姓名=N'{1}',部門代號=N'{2}',成本中心代號=N'{3}',電話號碼=N'{4}' where 天車人員代號=N'{5}'", txt天車人員代號.Text, txt人員姓名.Text, txt部門代號_天車人員.Text, txt成本中心代號_天車人員.Text, txt電話號碼.Text, id);
                PublicClass.InsertEditDeleteCommand("更新", strcmd, "Viewtiancherenyuan", dtgv天車人員List);//天車人員
                PublicClass.SearchTiancherenyuan(dtgv天車人員List, _txt天車人員代號.Text, _txt人員姓名.Text, _txt部門名稱.Text, _txt成本中心名稱.Text, _txt電話號碼.Text);
                txt天車人員代號.ResetText();
                txt人員姓名.ResetText();
                txt成本中心代號_天車人員.ResetText();
                txt電話號碼.ResetText();
                txt部門代號_天車人員.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        }

        private void btn_刪除_天車人員_Click(object sender, EventArgs e)
        {
            if (!b天車Del) btn_刪除_天車人員.Enabled = false;
            try
            {
                int r = dtgv天車人員List.CurrentCell.RowIndex;
                string id = dtgv天車人員List.Rows[r].Cells[0].Value.ToString();
                string strcmd = String.Format("delete from 天車人員 where 天車人員代號=N'{0}'",id);
                PublicClass.InsertEditDeleteCommand("刪除", strcmd, "天車人員", dtgv天車人員List);
                PublicClass.SearchTiancherenyuan(dtgv天車人員List, _txt天車人員代號.Text, _txt人員姓名.Text, _txt部門名稱.Text, _txt成本中心名稱.Text, _txt電話號碼.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_查詢_成本中心代號_Click(object sender, EventArgs e)
        {
            frm天車成本中心 frm = new frm天車成本中心(txt成本中心代號_天車人員);
            frm.ShowDialog();
        }

        private void btn_查詢_部門代號_Click(object sender, EventArgs e)
        {
            try
            {
                frm天車部門 frm = new frm天車部門(txt部門代號_天車人員);
                frm.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void groupBox18_Enter(object sender, EventArgs e)
        {

        }

        private void dtgv天車人員List_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //try
            //{
            //    SqlConnection con = new SqlConnection(connectionstring);
            //    con.Open();
            //    int r=e.RowIndex;
            //    string id = dtgv天車人員List.Rows[r].Cells[0].Value.ToString();
            //    txt天車人員代號.Text = id;
            //    txt人員姓名.Text = dtgv天車人員List.Rows[r].Cells[1].Value.ToString();
            //    txt電話號碼.Text = dtgv天車人員List.Rows[r].Cells[4].Value.ToString();
            //    string strcmd = String.Format("select * from ViewtiancherenyuanId where 天車人員代號=N'{0}'",id);
            //    SqlCommand cmd = new SqlCommand(strcmd, con);
            //    SqlDataReader reader = cmd.ExecuteReader();
            //    while (reader.Read())
            //    {
            //        txt部門代號_天車人員.Text = reader["部門代號"].ToString();
            //        txt成本中心代號_天車人員.Text = reader["成本中心代號"].ToString();
            //    }

            //    con.Close();               
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
        }

        private void button4_Click(object sender, EventArgs e)
        {

        }

        private void btn_changehidecrane_Click(object sender, EventArgs e)
        {
            if (btn_changehidecrane.Text == "+")
            {
                btn_changehidecrane.Text = "-";
                groupbox天車輸入.Visible = true;
            }
            else
            {
                btn_changehidecrane.Text = "+";
                groupbox天車輸入.Visible = false;
                txt天車編號_天車.ResetText();
                txt天車人員_天車.ResetText();
                txt額定荷重_天車.ResetText();
                txt功能_天車.ResetText();
                txt廠牌_天車.ResetText();
                txt生產序號_天車.ResetText();
                dtp生產日期_天車.Value = DateTime.Now;
                dtp安裝日期_天車.Value = DateTime.Now;
                dtp初次取證日_天車.Value = DateTime.Now;
            }

        }

        private void btn_Search_天車人員_Click(object sender, EventArgs e)
        {
            frm天車人員 frm = new frm天車人員(txt天車人員_天車);
            frm.ShowDialog();
        }

        private void btn_Search_額定荷重_Click(object sender, EventArgs e)
        {
            frm天車額定荷重 frm = new frm天車額定荷重(txt額定荷重_天車);
            frm.ShowDialog();
        }

        private void btn_Search_功能_Click(object sender, EventArgs e)
        {
            frm天車功能 frm = new frm天車功能(txt功能_天車);
            frm.ShowDialog();
        }

        private void btn_Search_廠牌_Click(object sender, EventArgs e)
        {
            frm天車廠牌 frm = new frm天車廠牌(txt廠牌_天車);
            frm.ShowDialog();
        }

        private void btn_新增_天車保養_Click(object sender, EventArgs e)
        {
            if (!b天車Insert) btn_新增_天車保養.Enabled = false;
            if (txt天車編號_保養.Text == "")
            {
                MessageBox.Show("您必須輸入天車編號","訊息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                txt天車編號_保養.Focus();
                return;
            }
            string strcmd = String.Format("insert into 天車保養 values(N'{0}',N'{1}',N'{2}',N'{3}')", txt天車編號_保養.Text, dtp預保日.Value.ToShortDateString(), dtp保養日.Value.ToShortDateString(),txt_備註_天車保養.Text);
            PublicClass.InsertEditDeleteCommand("新增", strcmd, "天車保養", dtgv天車保養List);
            PublicClass.SearchByTwo("天車保養", "預保日", "保養日", dtgv天車保養List, _txt天車編號.Text, dtp預保日from.Value, dtp預保日to.Value, dtp保養日from.Value, dtp保養日to.Value);
            txt天車編號_保養.ResetText();
            dtp預保日.Value = DateTime.Now;
            dtp保養日.Value = DateTime.Now;
            txt_備註_天車保養.ResetText();
        }

        private void btn_changehide_天車保養_Click(object sender, EventArgs e)
        {
            if (btn_changehide_天車保養.Text == "+")
            {
                btn_changehide_天車保養.Text = "-";
                groupbox天車保養.Visible = true;
            }
            else
            {
                btn_changehide_天車保養.Text = "+";
                groupbox天車保養.Visible = false;
                txt天車編號_保養.ResetText();
                dtp預保日.Value = DateTime.Now;
                dtp保養日.Value = DateTime.Now;
                txt_備註_天車保養.ResetText();
            }
        }

        private void dtgv天車保養List_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //try
            //{
            //    int r = e.RowIndex;
            //    txt天車編號_保養.Text = dtgv天車保養List.Rows[r].Cells[0].Value.ToString();
            //    dtp預保日.Value = (DateTime)dtgv天車保養List.Rows[r].Cells[1].Value;
            //    dtp保養日.Value = (DateTime)dtgv天車保養List.Rows[r].Cells[2].Value;
            //    txt_備註_天車保養.Text = dtgv天車保養List.Rows[r].Cells[3].Value.ToString();
               
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
        }

        private void btn_更新_天車保養_Click(object sender, EventArgs e)
        {
            if (!b天車Edit) btn_更新_天車保養.Enabled = false;
            try
            {
                if (txt天車編號_保養.Text == "")
                {
                    MessageBox.Show("您必須輸入天車編號", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txt天車編號_保養.Focus();
                    return;
                }
                int r=dtgv天車保養List.CurrentCell.RowIndex;
                string id=dtgv天車保養List.Rows[r].Cells[0].Value.ToString();
                DateTime dt=(DateTime)dtgv天車保養List.Rows[r].Cells[1].Value;

                string strcmd = String.Format("update 天車保養 set 天車編號=N'{0}',預保日=N'{1}',保養日=N'{2}',備註=N'{3}' where 天車編號=N'{4}'and 預保日=N'{5}'", txt天車編號_保養.Text, dtp預保日.Value.ToShortDateString(), dtp保養日.Value.ToShortDateString(),txt_備註_天車保養.Text,id,dt.ToShortDateString());
                PublicClass.InsertEditDeleteCommand("更新",strcmd,"天車保養",dtgv天車保養List);
                PublicClass.SearchByTwo("天車保養", "預保日", "保養日", dtgv天車保養List, _txt天車編號.Text, dtp預保日from.Value, dtp預保日to.Value, dtp保養日from.Value, dtp保養日to.Value);
                txt天車編號_保養.ResetText();
                dtp預保日.Value = DateTime.Now;
                dtp保養日.Value = DateTime.Now;
                txt_備註_天車保養.ResetText();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_刪除_天車保養_Click(object sender, EventArgs e)
        {
            if (!b天車Del) btn_刪除_天車保養.Enabled = false;
            try
            {
                int r = dtgv天車保養List.CurrentCell.RowIndex;
                string id = dtgv天車保養List.Rows[r].Cells[0].Value.ToString();
                DateTime dt = (DateTime)dtgv天車保養List.Rows[r].Cells[1].Value;
                string strcmd = String.Format("delete from 天車保養 where 天車編號=N'{0}'and 預保日=N'{1}'",id,dt.ToShortDateString());
                PublicClass.InsertEditDeleteCommand("刪除", strcmd, "天車保養", dtgv天車保養List);
                PublicClass.SearchByTwo("天車保養", "預保日", "保養日", dtgv天車保養List, _txt天車編號.Text, dtp預保日from.Value, dtp預保日to.Value, dtp保養日from.Value, dtp保養日to.Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_search_天車保養_Click(object sender, EventArgs e)
        {
            if (!b天車Search) btn_search_天車保養.Enabled = false;
            PublicClass.SearchByTwo("天車保養", "預保日", "保養日", dtgv天車保養List, _txt天車編號.Text, dtp預保日from.Value, dtp預保日to.Value, dtp保養日from.Value, dtp保養日to.Value);

        }

        private void dtgv天車保養List_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgv天車保養List);
        }

        private void btn_allrecord_Click(object sender, EventArgs e)
        {
            if (!b天車Search) btn_allrecord.Enabled = false;
            try
            {
                _txt天車編號.ResetText();
                dtp預保日from.Value = dtp預保日from.MinDate;
                dtp預保日to.Value = dtp預保日to.MaxDate;

                dtp保養日from.Value = dtp保養日from.MinDate;
                dtp保養日to.Value = dtp保養日to.MaxDate;
                PublicClass.SearchByTwo("天車保養", "預保日", "保養日", dtgv天車保養List, _txt天車編號.Text, dtp預保日from.Value, dtp預保日to.Value, dtp保養日from.Value, dtp保養日to.Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void btn_changehide_天車點檢_Click(object sender, EventArgs e)
        {
            if (btn_changehide_天車點檢.Text == "+")
            {
                btn_changehide_天車點檢.Text = "-";
                groupbox天車點檢輸入.Visible = true;
            }
            else
            {
                btn_changehide_天車點檢.Text = "+";
                groupbox天車點檢輸入.Visible = false;
                txt天車代號_天車點檢.ResetText();
                dtp點檢日期.ResetText();
                txt備註_天車點檢.ResetText();
            }
        }

        private void dtgv天車點檢List_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //try
            //{
            //    int i = e.RowIndex;
            //    txt天車代號_天車點檢.Text = dtgv天車點檢List.Rows[i].Cells[0].Value.ToString();
            //    DateTime dt = (DateTime)dtgv天車點檢List.Rows[i].Cells[1].Value;
            //    dtp點檢日期.Value = dt;
            //    txt備註_天車點檢.Text = dtgv天車點檢List.Rows[i].Cells[2].Value.ToString();
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
        }

        private void btn_Search_天車點檢_Click(object sender, EventArgs e)
        {
            if (!b天車Search) btn_Search_天車點檢.Enabled = false;
            PublicClass.SearchByOne("天車點檢", "點檢日期", dtgv天車點檢List, _txt天車代號_天車點檢.Text, dtp點檢日期from.Value, dtp點檢日期to.Value);
        }

        private void btn_all_天車點檢_Click(object sender, EventArgs e)
        {
            if (!b天車Search) btn_all_天車點檢.Enabled = false;
            _txt天車代號_天車點檢.ResetText();
            dtp點檢日期from.Value = dtp點檢日期from.MinDate;
            dtp點檢日期to.Value = dtp點檢日期to.MaxDate;
            PublicClass.SearchByOne("天車點檢", "點檢日期", dtgv天車點檢List, _txt天車代號_天車點檢.Text, dtp點檢日期from.Value, dtp點檢日期to.Value);
        }

        private void btn_search天車編號_Click(object sender, EventArgs e)
        {
            frm天車編號選項 frm = new frm天車編號選項(txt天車編號_保養);
            frm.ShowDialog();
        }

        private void btn_search_tianchebianhaodianjian_Click(object sender, EventArgs e)
        {
            frm天車編號選項 frm = new frm天車編號選項(txt天車代號_天車點檢);
            frm.ShowDialog();
        }

        private void btn_Search天車代號_Click(object sender, EventArgs e)
        {
            frm天車編號選項 frm = new frm天車編號選項(txt天車編號_天車維修);
            frm.ShowDialog();
        }

        private void btn_查詢_天車巡檢_Click(object sender, EventArgs e)
        {
            frm天車編號選項 frm = new frm天車編號選項(txt天車編號_天車巡檢);
            frm.ShowDialog();
        }

        private void btn_查詢_天車人員_Click(object sender, EventArgs e)
        {
            if (!b天車Search) btn_查詢_天車人員.Enabled = false;
            PublicClass.SearchTiancherenyuan(dtgv天車人員List, _txt天車人員代號.Text, _txt人員姓名.Text, _txt部門名稱.Text, _txt成本中心名稱.Text, _txt電話號碼.Text);
        }

        private void btn_all_tiancherenyuan_Click(object sender, EventArgs e)
        {
            if (!b天車Search) btn_all_tiancherenyuan.Enabled = false;
            _txt天車人員代號.ResetText();
            _txt人員姓名.ResetText();
            _txt部門名稱.ResetText();
            _txt成本中心名稱.ResetText();
            _txt電話號碼.ResetText();
            PublicClass.SearchTiancherenyuan(dtgv天車人員List, _txt天車人員代號.Text, _txt人員姓名.Text, _txt部門名稱.Text, _txt成本中心名稱.Text, _txt電話號碼.Text);
        }

        private void btnSearchTiancheinfo_Click(object sender, EventArgs e)
        {
            if (!b天車Search) btnSearchMain.Enabled = false;
            PublicClass.SearchTiancheInfo(dtgv天車List, txt天車編號s.Text, txt額定荷重s.Text, txt功能s.Text, txt廠牌s.Text, txt生產序號s.Text, dtp生產日期天車from.Value, dtp生產日期天車to.Value, dtp安裝日期天車from.Value, dtp安裝日期天車to.Value, dtp初次取證日from.Value, dtp初次取證日天車to.Value, txt部門s.Text, txt成本中心s.Text, txt天車人員s.Text, txt電話s.Text);
        }

        private void btn_All_tiancheinfo_Click(object sender, EventArgs e)
        {
            if (!b天車Search) btn_All_tiancheinfo.Enabled = false;
            txt天車編號s.ResetText();
            txt額定荷重s.ResetText();
            txt功能s.ResetText();
            txt廠牌s.ResetText();
            txt生產序號s.ResetText();//dtp安裝日期天車from
            txt部門s.ResetText();
            txt成本中心s.ResetText();
            txt天車人員s.ResetText();
            txt電話s.ResetText();
            dtp生產日期天車from.Value = dtp安裝日期天車from.MinDate;
            dtp生產日期天車to.Value = dtp安裝日期天車from.MaxDate;

            dtp安裝日期天車from.Value = dtp安裝日期天車from.MinDate;
            dtp安裝日期天車to.Value = dtp安裝日期天車from.MaxDate;

            dtp初次取證日from.Value = dtp安裝日期天車from.MinDate;
            dtp初次取證日天車to.Value = dtp安裝日期天車from.MaxDate;

          

            PublicClass.SearchTiancheInfo(dtgv天車List, txt天車編號s.Text, txt額定荷重s.Text, txt功能s.Text, txt廠牌s.Text, txt生產序號s.Text, dtp生產日期天車from.Value, dtp生產日期天車to.Value, dtp安裝日期天車from.Value, dtp安裝日期天車to.Value, dtp初次取證日from.Value, dtp初次取證日天車to.Value, txt部門s.Text, txt成本中心s.Text, txt天車人員s.Text, txt天車人員s.Text);
        }

        private void dtgv天車List_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //try
            //{
            //    SqlConnection con = new SqlConnection(connectionstring);
            //    con.Open();
            //    int r = e.RowIndex;
            //    string id = dtgv天車List.Rows[r].Cells[0].Value.ToString();
            //    txt天車編號_天車.Text = id;
            //    string strcmd = String.Format("select * from 天車 where 天車編號=N'{0}'",id);
            //    SqlCommand cmd = new SqlCommand(strcmd, con);
            //    SqlDataReader reader = cmd.ExecuteReader();
            //    while (reader.Read())
            //    {
            //        txt天車人員_天車.Text = reader["天車人員代號"].ToString();
            //        txt額定荷重_天車.Text = reader["額定荷重代號"].ToString();
            //        txt功能_天車.Text = reader["功能代號"].ToString();
            //        txt廠牌_天車.Text = reader["廠牌代號"].ToString();
            //        txt生產序號_天車.Text = reader["生產序號"].ToString();
            //        dtp生產日期_天車.Value = (DateTime)reader["生產日期"];
            //        dtp安裝日期_天車.Value = (DateTime)reader["安裝日期"];
            //        dtp初次取證日_天車.Value = (DateTime)reader["初次取證日"];

            //    }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
        }

        private void dtgv天車List_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgv天車List);
        }

        private void dtgv天車List_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(connectionstring);
                con.Open();
                int r = e.RowIndex;
                string id = dtgv天車List.Rows[r].Cells[0].Value.ToString();
                txt天車編號_天車.Text = id;
                string strcmd = String.Format("select * from 天車 where 天車編號=N'{0}'", id);
                SqlCommand cmd = new SqlCommand(strcmd, con);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    txt天車人員_天車.Text = reader["天車人員代號"].ToString();
                    txt額定荷重_天車.Text = reader["額定荷重代號"].ToString();
                    txt功能_天車.Text = reader["功能代號"].ToString();
                    txt廠牌_天車.Text = reader["廠牌代號"].ToString();
                    txt生產序號_天車.Text = reader["生產序號"].ToString();
                    dtp生產日期_天車.Value = (DateTime)reader["生產日期"];
                    dtp安裝日期_天車.Value = (DateTime)reader["安裝日期"];
                    dtp初次取證日_天車.Value = (DateTime)reader["初次取證日"];

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgv天車人員List_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(connectionstring);
                con.Open();
                int r = e.RowIndex;
                string id = dtgv天車人員List.Rows[r].Cells[0].Value.ToString();
                txt天車人員代號.Text = id;
                txt人員姓名.Text = dtgv天車人員List.Rows[r].Cells[1].Value.ToString();
                txt電話號碼.Text = dtgv天車人員List.Rows[r].Cells[4].Value.ToString();
                string strcmd = String.Format("select * from ViewtiancherenyuanId where 天車人員代號=N'{0}'", id);
                SqlCommand cmd = new SqlCommand(strcmd, con);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    txt部門代號_天車人員.Text = reader["部門代號"].ToString();
                    txt成本中心代號_天車人員.Text = reader["成本中心代號"].ToString();
                }

                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgv天車人員List_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgv天車人員List);
        }

        private void btn_clearall_tiancherenyuan_Click(object sender, EventArgs e)
        {
            txt天車編號_天車.ResetText();
            txt天車人員_天車.ResetText();
            txt額定荷重_天車.ResetText();
            txt功能_天車.ResetText();
            txt廠牌_天車.ResetText();
            txt生產序號_天車.ResetText();
            dtp生產日期_天車.Value = DateTime.Now;
            dtp安裝日期_天車.Value = DateTime.Now;
            dtp初次取證日_天車.Value = DateTime.Now;
        }

        private void btn_clear_tiancherenyuan_Click(object sender, EventArgs e)
        {
            txt天車人員代號.ResetText();
            txt人員姓名.ResetText();
            txt成本中心代號_天車人員.ResetText();
            txt電話號碼.ResetText();
            txt部門代號_天車人員.ResetText();
        }

        private void btn_changehide_tiancheweixiu_Click(object sender, EventArgs e)
        {
            try
            {
                if (btn_changehide_tiancheweixiu.Text == "+")
                {
                    btn_changehide_tiancheweixiu.Text = "-";
                    groupboxtiancheweixiushuru.Visible = true;
                }
                else
                {
                    btn_changehide_tiancheweixiu.Text = "+";
                    groupboxtiancheweixiushuru.Visible = false;
                    dtp維修日期.ResetText();
                    txt天車編號_天車維修.ResetText();
                    txt備註_天車維修.ResetText();
                }
            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_resetall_tiancheweixiu_Click(object sender, EventArgs e)
        {
            dtp維修日期.ResetText();
            txt天車編號_天車維修.ResetText();
            txt備註_天車維修.ResetText();
        }

        private void btn_search_tiancheweixiu_Click(object sender, EventArgs e)
        {
            if (!b天車Search) btn_search_tiancheweixiu.Enabled = false;
            PublicClass.SearchByOne("天車維修", "維修日期", dtgv天車維修List,_txt天車編號s.Text, dtp天車維修from.Value, dtp天車維修to.Value);
        }

        private void btn_changeHidexunjian_Click(object sender, EventArgs e)
        {
            try
            {
                if (btn_changeHidexunjian.Text == "+")
                {
                    btn_changeHidexunjian.Text = "-";
                    groupbox巡檢輸入.Visible = true;
                }
                else
                {
                    btn_changeHidexunjian.Text = "+";
                    groupbox巡檢輸入.Visible = false;
                    txt天車編號_天車巡檢.ResetText();
                    dtp巡檢日期.ResetText();
                    txt備註_天車巡檢.ResetText();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_clear_xunjianshuru_Click(object sender, EventArgs e)
        {
            txt天車編號_天車巡檢.ResetText();
            dtp巡檢日期.ResetText();
            txt備註_天車巡檢.ResetText();
        }

        private void btn_search_tianchexunjian_Click(object sender, EventArgs e)
        {
            if (!b天車Search) btn_search_tianchexunjian.Enabled = false;
            PublicClass.SearchByOne("天車巡檢", "巡檢日期", dtgv天車巡檢List, txt天車id.Text, dtp巡檢日期from.Value, dtp巡檢日期to.Value);
        }

        private void btn_resetall_tianchexunjian_Click(object sender, EventArgs e)
        {
            if (!b天車Search) btn_resetall_tianchexunjian.Enabled = false;
            txt天車id.ResetText();
            dtp巡檢日期from.Value = dtp巡檢日期from.MinDate;
            dtp巡檢日期to.Value = dtp巡檢日期from.MaxDate;
            PublicClass.SearchByOne("天車巡檢", "巡檢日期", dtgv天車巡檢List, txt天車id.Text, dtp巡檢日期from.Value, dtp巡檢日期to.Value);
        }

        private void dtgv天車保養List_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int r = e.RowIndex;
                txt天車編號_保養.Text = dtgv天車保養List.Rows[r].Cells[0].Value.ToString();
                dtp預保日.Value = (DateTime)dtgv天車保養List.Rows[r].Cells[1].Value;
                dtp保養日.Value = (DateTime)dtgv天車保養List.Rows[r].Cells[2].Value;
                txt_備註_天車保養.Text = dtgv天車保養List.Rows[r].Cells[3].Value.ToString();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_resetl_tianchedianjianshuru_Click(object sender, EventArgs e)
        {
            txt天車代號_天車點檢.ResetText();
            dtp點檢日期.ResetText();
            txt備註_天車點檢.ResetText();
        }

        private void btn_reset_tianchebaoyangshuru_Click(object sender, EventArgs e)
        {
            txt天車編號_保養.ResetText();
            dtp預保日.Value = DateTime.Now;
            dtp保養日.Value = DateTime.Now;
            txt_備註_天車保養.ResetText();
        }

        private void btn_all_tiancheweixiu_Click(object sender, EventArgs e)
        {
            if (!b天車Search) btn_all_tiancheweixiu.Enabled = false;
            _txt天車編號s.ResetText();
            dtp天車維修from.Value = dtp天車維修from.MinDate;
            dtp天車維修to.Value = dtp天車維修from.MaxDate;
            PublicClass.SearchByOne("天車維修", "維修日期", dtgv天車維修List, _txt天車編號s.Text, dtp天車維修from.Value, dtp天車維修to.Value);
        }

        private void btnReport_Click(object sender, EventArgs e)
        {
            try
            {
                if (!b天車Search) btnReporttianche.Enabled = false;
                Export_Excel excel = new Export_Excel();
                DataTable dt = (DataTable)dtgv天車保養List.DataSource;
                excel.Export(dt, "Sheet1", "天車資訊");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnReporttianche_Click(object sender, EventArgs e)
        {
            try
            {
                if (!b天車Search) btnReporttianche.Enabled = false;
                Export_Excel excel = new Export_Excel();
                DataTable dt = (DataTable)dtgv天車List.DataSource;
                excel.Export(dt, "Sheet1", "天車報告");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        

    }
}
